from django.shortcuts import render,HttpResponse
# Create your views here.
from blog.models import Article
def index(request):
    print("请求blog index界面:",request)
    #跳到这个界面：blog_index.html
    # 创建article数据包括:title,author,price,content,pub_date,status
    # article = Article(title='测试标题',author='测试作者',price=100,content='测试内容',pub_date='2025-04-11 12:30',status=0)
    # result = article.save()
    # print("打印出结果", result)
    #查询article数据
    # articles = Article.objects.all()
    # for article in articles:
    #     print("打印出article数据：",end="")
    #     print(article.title,article.author,article.price,article.content,article.pub_date,article.status)
    # 查询 文章为Python的内容
    articles = Article.objects.filter(title='Python')
    article1={}
    for article in articles:
        article1 = {
            'title':article.title,
            'author':article.author,
            'price':article.price,
            'content':article.content,
            'pub_date':article.pub_date,
            'status':article.status
        }
    print("打印出article1数据：",article1)
    return render(request,"blog/blog_index.html",{'article':article1})


def article_detail(request,article_id):
    print("article_id:",article_id)
    return HttpResponse(f"<h2>文章详情：{article_id}</h2>")

def archive(request,year,month):
    print(f"===========>year:{year},month:{month}")
    return HttpResponse(f"<h2>文章归档：{year}年{month}月</h2>")

def to_login(request):
    print("跳转到登录界面")
    return render(request,"cursor-login.html")